<?php
 require("config/config.php");
 require("common.php");
 $mysql = new SaeMysql();
 $bid= strip_tags( $_REQUEST['bid'] );
 
 if(is_numeric($bid)){
 	$sql = "SELECT bottle.bid, bottle.date, bottle.content, bottle.anony, bottle.golden, user.nake, bottle.deleteuid FROM `bottle`,`user` WHERE bottle.uid=user.uid AND bid=".$bid;
	$data = $mysql->getData( $sql );
 }else{
	 $sql = "SELECT bottle.bid, bottle.date, bottle.content, bottle.anony, bottle.golden, user.nake, bottle.deleteuid FROM `bottle`,`user` WHERE bottle.uid=user.uid ORDER BY rand() LIMIT 1";
	 $data = $mysql->getData( $sql );
	 $rs=$data[0];
	 $bid = $rs[bid];
	 $deleteuid= $rs[deleteuid];
	 
	//if deleted, next
	 while($deleteuid != 0){
	 	$bid ++;
	 	 $sql = "SELECT bottle.bid, bottle.date, bottle.content, bottle.anony, bottle.golden, user.nake, bottle.deleteuid FROM `bottle`,`user` WHERE bottle.uid=user.uid AND bid=".$bid;
		 $data = $mysql->getData( $sql );
		 $rs=$data[0];
		 $bid = $rs[bid];
		 $deleteuid= $rs[deleteuid];
	 }
 }
  
 if( $mysql->errno() != 0 )
 {
	echo "false";
 }else{
 	echo myjson($data );
 }
 
$mysql->closeDb();
?>